#include "mycombobox.h"

MyComboBox::MyComboBox(QWidget *parent)
    : QComboBox(parent), m_bCanUse(true), m_focusWidget(NULL) {
  QStyledItemDelegate *itemDelegate = new QStyledItemDelegate();
  this->setItemDelegate(itemDelegate);

  this->setFocusPolicy(Qt::NoFocus);
}
MyComboBox::~MyComboBox() {}

void MyComboBox::mousePressEvent(QMouseEvent *event) {
  if (event->button() == Qt::LeftButton) {
    emit clicked();
    if (!m_bCanUse) {
      m_bCanUse = true;
      return;
    }
  }

  QComboBox::mousePressEvent(event);
}

void MyComboBox::hidePopup() {
  if (m_focusWidget != NULL) {
    m_focusWidget->setFocus();
  }

  QComboBox::hidePopup();
}
